//
//  YCPushPopViewController.m
//  DemoTransition
//
//  Created by yunsheng on 15/7/22.
//  Copyright (c) 2015年 yunsheng. All rights reserved.
//

#import "YCPushPopViewController.h"

#import "YCPushPopDetailViewController.h"
#import "YCVCsPushTransition.h"

@interface YCPushPopViewController ()<UINavigationControllerDelegate>

@end

@implementation YCPushPopViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
    self.navigationController.delegate = self;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - UICollectionViewDataSource, UICollectionViewDelegate

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 10;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellId = @"cellImg";
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellId forIndexPath:indexPath];
    
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    self.selectedCell = (YCPushPopCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
    
    [self performSegueWithIdentifier:@"toPushPopDetail" sender:nil];
}

#pragma mark - UINavigationControllerDelegate

-(id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC
{
    if (operation == UINavigationControllerOperationPush) {
        return [[YCVCsPushTransition alloc] init];
    } else {
        return nil;
    }
}

#pragma mark - method

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"toPushPopDetail"]) {
        YCPushPopDetailViewController *vc = segue.destinationViewController;
        vc.image = self.selectedCell.imageView.image;
    }
}

@end
